package org.raymond.iworks.study.mq.rabbitmq.classic.pull;

import com.rabbitmq.client.*;
import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.study.mq.rabbitmq.classic.hello.Send;

import java.nio.charset.StandardCharsets;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class GetWorker {
    public static void main(String[] args) throws Exception {
        try (Connection connection = Send.connection();
             Channel channel = connection.createChannel()) {
            channel.queueDeclare(Send.QUEUE_NAME, true, false, false, null);

            GetResponse response = channel.basicGet(Send.QUEUE_NAME, true); // true to auto-acknowledge the message
            if (response != null) {
                String message = new String(response.getBody(), StandardCharsets.UTF_8);
                log.info("Received message: " + message);
            } else {
                log.info("No message available in the queue.");
            }
        }
    }


}
